package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.SaleOrder;
import com.example.demo.mapper.SaleOrderMapper;
import com.example.demo.service.ISaleOrderService;
import com.example.demo.strategy.BizMethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cici
 */
@Service
public class SaleOrderServiceImpl extends BaseOrderService<SaleOrderMapper, SaleOrder> implements ISaleOrderService {

    @Autowired
    private BizMethodService methodService;

    @Override
    public SaleOrder create(SaleOrder saleOrder) {
        commonLogic();
        methodService.doBizMethod(2);
        saleOrder.setTotalMoney(calculateTotalMoney(saleOrder));
        baseMapper.insert(saleOrder);
        return baseMapper.selectById(saleOrder.getId());
    }

    @Override
    public SaleOrder detail(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public IPage<SaleOrder> selectPage(Page<SaleOrder> page, SaleOrder saleOrder) {
        return baseMapper.selectPageByCondition(page,saleOrder);
    }

    @Override
    public Boolean delete(Integer id) {
        int res = baseMapper.deleteById(id);
        if (res>0){
            return true;
        }
        return false;
    }
}
